var terminalDetailController = function($scope, $http, $location, LoginService) {
	$scope.terminalId = Math.ceil($location.search()['terminalId']);
	$scope.customerId = Math.ceil(LoginService.agentUserId);
	$(".leaseExplain_tab").hide();
	$("#pass").hide();
	// 显示终端详情
	$scope.terminalShow = false;
	// 查看终端详情
	$scope.terminalDetail = function() {
		// 获取终端详情
		$http.post("api/webTerminal/getWebApplyDetail", {
			terminalsId : $scope.terminalId
		}).success(function(data) { // 绑定
			if (data != null && data != undefined) {
				if (data.code == 1) {
					// 终端信息
					$scope.applyDetails = data.result.applyDetails;
					// 交易
					$scope.rateList = data.result.rates;
					// 租赁
					$scope.tenancy = data.result.tenancy;
					// 开通基本资料
					$scope.openingInfos = data.result.openingInfos;
					// 资料
					$scope.openingDetails = data.result.openingDetails;
					// 追踪记录
					$scope.trackRecord = data.result.trackRecord;
					if ($scope.openingInfos != null) {
						$scope.terminalShow = true;
					}
				}
			}
		}).error(function(data) {
			alert("获取列表失败");
		});
	};

	// 申请注销判断
	$scope.judgeRentalReturn = function() {
		$http.post("api/webTerminal/judgeRentalReturn", {
			terminalid : $scope.terminalId
		}).success(function(data) { // 绑定
			if (data != null && data != undefined) {
				if (data.code == -1) {
					alert("已有该终端注销申请！");
				} else if (data.code == 1) {
					window.location.href = "#/terminalCancellation?terminalId=" + $scope.terminalId;

				}
			}
		}).error(function(data) {
			alert("操作失败！");
		});
	}

	// 下载资料
	$scope.updownfile = function(id) {
		$http.post("api/webTerminal/noticeMaterial/" + id, {
			terminalid : $scope.terminalId
		}).success(function(data) { // 绑定
			if (data != null && data != undefined) {
				if (data.code == -1) {
					alert(data.message);
				} else if (data.code == 1) {
					window.location.href = data.result;
				}
			}
		}).error(function(data) {
			alert("操作失败！");
		});
	}

	// 申请更新判断
	$scope.judgeUpdate = function() {
		$http.post("api/webTerminal/judgeUpdate", {
			terminalid : $scope.terminalId
		}).success(function(data) { // 绑定
			if (data != null && data != undefined) {
				if (data.code == -1) {
					alert("已有该终端更新申请！");
				} else if (data.code == 1) {
					window.location.href = "#/terminalToUpdate?terminalId=" + $scope.terminalId;

				}
			}
		}).error(function(data) {
			alert("操作失败！");
		});
	}

	// 找回POS机密码
	$scope.pass = null;
	$scope.findPassword = function(t) {
		$http.post("api/webTerminal/Encryption", {
			terminalid : $scope.terminalId
		}).success(function(data) { // 绑定
			if (data != null && data != undefined) {
				if (data.code == 1) {
					$("#passdiv").html(data.result);
					$scope.showPay(t);
				}
			}
		}).error(function(data) {
			alert("获取列表失败");
		});
	}
	// 同步
	$scope.sync = function() {
		$http.post("api/webTerminal/synchronous", {
			terminalId : $scope.terminalId
		}).success(function(data) { // 绑定
			if (data != null && data != undefined) {
				if (data.code == -1) {
					alert("同步失败！");
				} else if (data.code == 1) {
					alert("同步成功！");
					window.location.reload();
				}
			}
		}).error(function(data) {
			alert("同步失败！");
		});
	}

	// 关闭弹出框
	$scope.closeDocument = function(obj) {
		$("#" + obj).hide();
		$(".mask").hide();
	}

	$scope.showPay = function(t) {
		var doc_height = $(document).height();
		var doc_width = $(document).width();
		var win_height = $(window).height();
		var win_width = $(window).width();

		var layer_height = $(t).height();
		var layer_width = $(t).width();

		var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;

		$(".mask").css({
			display : 'block',
			height : doc_height
		});
		$(t).css('top', (win_height - layer_height) / 2);
		$(t).css('left', (win_width - layer_width) / 2);
		$(t).css('display', 'block');

	};

	$scope.close = function(t) {
		$(t).css('display', 'none');
		$(".mask").css('display', 'none');
	}

	$scope.onmousover = function() {
		infoTab('.cover', '.img_info');
	}
	// 鼠标经过小图提示大图
	function infoTab(i_tab, i_box) {

		$(i_tab).hover(

		function(e) {
			$(i_box).children("img").attr("src", $(this).attr('path'));
			$(i_box).css('display', 'block');
			$(i_box).css('top', $(this).offset().top - $(i_box).height() + 'px');

			if ($(this).offset().left + $(i_box).width() > $(document).width()) {
				$(i_box).css('left', ($(this).offset().left) - $(i_box).width() + 'px');
			} else {
				$(i_box).css('left', ($(this).offset().left) + $(this).width() + 'px');
			}
		}, function(e) {
			$(i_box).children("img").attr("src", "");
			$(i_box).css('display', 'none');
			$(i_box).css({
				'top' : 0 + 'px',
				'left' : 0 + 'px'
			});
		});
	}

	$scope.terminalDetail();
	$scope.onmousover();

};